<!--
 * @Author: 祝肖 1738052358@qq.com
 * @Date: 2024-03-13 10:00:42
 * @LastEditTime: 2024-03-29 16:50:52
 * @LastEditors: 冯尚新 fengshangxin@yunjinhz.com
 * @Description: 打假打私统计
 * @FilePath: \zmglpt-ui-mobile-v1.1\dev\pages\internal\falsePrivacy\falsePrivacyStatic.vue
 * 可以输入预定的版权声明、个性签名、空行等
-->
<template>
  <view>
    <!-- #ifdef H5-ONLY -->
    <theme-navbar :is-white="false" :title="title" :custom-back="goBack" style="z-index: 99999">
      <view class="nav-right-icon">
        <u-icon name="reload" color="#FFF" @tap="refreshTb()"></u-icon>
        <u-icon style="margin-left: 20rpx" name="more-dot-fill" color="#FFF" @tap="orgShow = true"></u-icon>
      </view>
    </theme-navbar>
    <!-- #endif -->
    <!-- #ifdef H5-DINGDING || H5-WECHAT || H5-EMP -->
    <fab-button :content="fContent" @fabtrigger="fabtrigger" />
    <!-- #endif -->
    <view style="height:100%;">
      <swiper
        :style="{ 'height': swiperHeight + 'px', }"
        :indicator-dots="tabList.length > 0"
        indicator-color="rgba(0,0,0,0.3)"
        indicator-active-color="#2979FF"
        :autoplay="autoplay"
        :interval="interval"
        :duration="duration"
        :current="current"
        @change="swiperChange"
      >
        <swiper-item class="swiper-item" v-if="tabList.length == 0">
          <u-empty text="没有数据" mode="list"></u-empty>
        </swiper-item>
        <template v-else>
          <swiper-item
            class="swiper-item"
            v-for="(item, index) in tabList"
            :key="'swiperItem' + index"
          >
            <view class="head-row">
              <u-row gutter="8" style="flex: 1">
                <u-col
                  :span="sItem.columnSpan || 3"
                  v-for="(sItem, sIndex) in item"
                  :key="'col' + index + sIndex"
                >
                  <view
                    class="head-title-lay"
                    :style="{
                  textAlign: sItem.align || 'center',
                  paddingRight: (sIndex == item.length - 1) ? '10rpx' : '0px',
                  justifyContent: (!sItem.align || sItem.align == 'center') ? 'center' : (sItem.align == 'right' ? 'flex-end' : 'flex-start'),
                }"
                  >
                    <view class="split-title" style="font-size: 15px">{{ sItem.label }}</view>
                  </view>
                </u-col>
              </u-row>
            </view>
            <template v-if="content && content.length == 0">
              <u-empty text="没有数据" mode="search"></u-empty>
            </template>
            <template v-else>
              <scroll-view
                :scroll-top="0"
                :style="{ height: getScrollHeight() }"
                :scroll-y="true"
                :scroll-x="false"
                class="scroll-Y table-body"
              >
                <u-row
                  v-for="(rowItem, rowIndex) in content"
                  :key="'rowContent' + index + rowIndex"
                  :class="'row-item row-lay ' + 'taped-item' + (Number(rowIndex)%2 ? 'taped-len' : '')"
                  gutter="20"
                  :needTapHover="true"
                >
                  <u-col
                    v-for="(cItem, cIndex) in item"
                    :key="'colcontent' + index + rowIndex + cIndex"
                    :span="cItem.columnSpan || 3"
                  >
                    <view
                      class="list-item split-val"
                      :style="{
                    paddingRight: (cIndex == item.length - 1) ? '10rpx' : '0px',
                    textAlign: cItem.align || 'center',
                    justifyContent: (!cItem.align || cItem.align == 'center') ? 'center' : (cItem.align == 'right' ? 'flex-end' : 'flex-start'),
                    color: contentColor(rowItem[cItem.fieldKey])
                  }"
                    >{{ filterNum(rowItem[cItem.fieldKey])}}</view>
                  </u-col>
                </u-row>
              </scroll-view>
            </template>
          </swiper-item>
        </template>
      </swiper>
      <u-popup v-model="orgShow" width="80%" mode="right">
        <view class="cearch_title">查询条件</view>
        <view class="title-content">
          <u-form :model="queryForm" :errorType="errorType" ref="uForm">
            <u-form-item label="时间类型" :label-position="labelPosition">
              <view style="margin-top:20rpx;margin-bottom: 10rpx; width:100%;">
                <u-subsection
                  :active-color="$theme.u_type_primary"
                  mode="subsection"
                  :list="logicSlist"
                  :current="queryForm.statDateType"
                  @change="logicChange"
                ></u-subsection>
              </view>
            </u-form-item>
            <u-form-item
              label="开始日期"
              :label-position="labelPosition"
              right-icon="arrow-right"
              prop="beginTime"
              ref="startChangeRef"
            >
              <u-input
                :disabled="true"
                placeholder="请选择日期"
                v-model="queryForm.startTime"
                @click="clicDatekHandle('isShowStart')"
              />
            </u-form-item>
            <u-form-item
              label="结束日期"
              :label-position="labelPosition"
              right-icon="arrow-right"
              prop="endTime"
              ref="endChangeRef"
            >
              <u-input
                :disabled="true"
                placeholder="请选择日期"
                v-model="queryForm.endTime"
                @click="clicDatekHandle('isShowEnd')"
              />
            </u-form-item>
          </u-form>
        </view>
        <view class="submit-btns btn-other-cls">
          <u-button plain class="del" type="primary" @click="resetForm">重置</u-button>
          <u-button class="mit" type="primary" @click="selectChange">确定</u-button>
        </view>
      </u-popup>
      <u-calendar v-model="showTime" :max-date="maxDate" mode="date" @change="timeChange"></u-calendar>
    </view>
  </view>
</template>
<script>
Number.prototype.toFixedNo = function(fixed) {
  let num = this;
  // 默认保留小数
  fixed = fixed || 0;
  // 如果fixed不是数字，直接返回
  if (isNaN(fixed)) {
    return num.toString();
  } else {
    let numStr = num.toString();
    // 如果num不是小数，返回
    if (numStr.indexOf(".") < 0 || numStr.indexOf(".") == numStr.length - 1) {
      return parseInt(num);
    } else if (fixed == 0) {
      let arr = numStr.split(".");
      let integer = arr[0];
      let decimals = arr[1];
      if (parseInt(decimals) != 0) {
        if (decimals.substr(0, 1) >= 5) {
          integer = parseInt(integer) + 1;
        }
      }
      return integer;
    } else {
      let arr = numStr.split(".");
      let integer = arr[0];
      let decimals = arr[1];

      if (fixed < decimals.length) {
        let fixedNo = decimals.substr(0, fixed);
        //  判断保留位的下一位是否大于5，四舍五入
        if (decimals.substr(fixed, 1) >= 5) {
          fixedNo = parseInt(fixedNo) + 1;
        } else {
          if (parseInt(fixedNo) == 0) {
            return integer;
          }
          // 移除多余的0
          fixedNo = fixedNo.replace(/0+$/, "");
        }
        1;
        decimals = fixedNo;
      }
      return integer + "." + decimals;
    }
  }
};
import fabButton from "@/components/uni-fab.vue";
import internalService from "@/service/internal/internal.service";
export default {
  components: {
    // meTable,
    // checkItem,
    fabButton
  },
  data() {
    return {
      title: "打假打私统计",
      swiperHeight: 500,
      autoplay: false,
      interval: 5000,
      duration: 500,
      current: 0,
      content: [],
      orgShow: false,
      maxDate: "2099-12-31",
      labelPosition: "top",
      showTime: false,
      timeId: "",
      orgUuid: "",
      fixedLimit: 2,
      user: this.$store.state.userInfo,
      errorType: ["border-bottom", "message"],
      normalTxtColor: "#393B3D",
      errorTxtColor: "#fa3534",
      queryForm: {
        statDateType: "01",
        startTime: "",
        endTime: ""
      },
      logicSlist: [
        { name: "申请时间", value: "01" },
        { name: "完成时间", value: "03" }
      ],
      fContent: [
        {
          iconPath: require("@/static/refresh.png"),
          selectedIconPath: require("@/static/refresh.png"),
          text: "刷新",
          active: false
        },
        {
          iconPath: require("@/static/sou.png"),
          selectedIconPath: require("@/static/sou.png"),
          text: "筛选",
          active: false
        }
      ],

      tabList: [
        [
          {
            label: "打假打私统计",
            fieldKey: "orgName",
            columnSpan: 4,
            hasSort: false,
            // unit: "起",
            align: "center"
          },
          {
            label: "大案快报总数(起)",
            fieldKey: "bigCaseNum",
            columnSpan: 4,
            hasSort: false,
            // unit: "起",
            align: "center"
          },
          {
            label: "联合办案数量(起)",
            fieldKey: "caseRelationNum",
            columnSpan: 4,
            unit: "起",
            hasSort: true,
            align: "center"
          }
        ],
        [
          {
            label: "部督案件数量(起)",
            fieldKey: "countryCaseSuperviseNum",
            columnSpan: 6,
            hasSort: true,
            align: "center"
          },
          {
            label: "省督案件数量(起)",
            fieldKey: "provCaseSuperviseNum",
            columnSpan: 6,
            hasSort: false,
            unit: "件",
            align: "center"
          }
        ],
        [
          {
            label: "国标重大案件数量(起)",
            fieldKey: "countryCaseSeriousNum",
            columnSpan: 6,
            hasSort: true,
            align: "center"
          },
          {
            label: "省标重大案件数量(起)",
            fieldKey: "provCaseSeriousNum",
            columnSpan: 6,
            hasSort: true,
            align: "center"
          }
        ]
      ]
    };
  },
  mounted() {
    this.init();
  },
  methods: {
    init() {
      // #ifdef H5-DINGDING
      this.swiperHeight = this.$u.sys().windowHeight - 50;
      // #endif
      // #ifndef H5-DINGDING
      this.swiperHeight = this.$u.sys().windowHeight - 44 - 50;
      // #endif
      //   commonService
      //     .queryAreaBaseByCode(this.user.user.org.orgUuid)
      //     .then(res => {
      //       if (!res.success) return;
      //       console.log(res)
      //     });;
      this.orgUuid = this.user.user.org.orgUuid; // 默认都用自己地区的code
      //   this.orginalData.header = this.tabList[this.tabCurrent].header;
      this.loadData();
    },
    loadData() {
      this.$modal.showLoading("查询中...");
      let params = {
        paras: {
          orgUuid: this.orgUuid,
          statDateType: this.queryForm.statDateType,
          startTime: this.queryForm.startTime,
          endTime: this.queryForm.endTime
        }
      };
      internalService
        .getCounterfeitingSmugglingReport(params)
        .then(res => {
          this.$modal.hideLoading();
          if (!res.success) return;
          this.content = res.data;
        })
        .catch(e => {
          this.$modal.hideLoading();
          console.log(e);
          this.$u.toast("查询失败");
        });
      //   this.loadData();
    },
    selectChange() {
      this.loadData();
      this.orgShow = false;
    },
    resetForm() {
      this.queryForm = {
        statDateType: "01",
        startTime: "",
        endTime: ""
      };
    },
    fabtrigger(act) {
      if (act.index === 0) {
        this.refreshTb();
      } else if (act.index === 1) {
        this.selectOrg();
      }
    },
    logicChange(e) {
      this.statDateType = e;
    },
    selectOrg() {
      this.orgShow = true;
    },
    swiperChange(e) {
      this.current = e.detail.current;
    },
    refreshTb() {
      // 刷新操作，刷新暂不重置筛选条件
      //   this.orgParam.parentOrgUuid = "";
      //   this.orgParam.parentOrgName = "";
      //   this.itemKeyUuid = "";
      // this.endDate = moment().subtract(1, 'days').format("YYYY-MM-DD");
      // this.curTimeStart = moment().startOf('year').format('YYYY-MM-DD');
      // this.curTimeEnd = moment().subtract(1, 'days').format("YYYY-MM-DD");this.user.user.org.orgUuid
      //   this.orgParam.orgUuid = this.user.user.org.orgUuid; // 默认都用省的code
      //   this.orgParam.orgLevel = "01"; // "0" + this.user.orgLevel;
      //   this.orgParam.orgName = this.orgParam.areaName;
      //   this.orgParam.orgRank = 1;
      //   this.hasTotal = true;
      this.loadData();
    },
    clicDatekHandle(type) {
      this.timeId = type;
      this.showTime = true;
    },
    timeChange(e) {
      this.showTime = false;
      if (this.timeId == "isShowStart") {
        this.queryForm.startTime = e.result;
      } else {
        this.queryForm.endTime = e.result;
      }
    },
    resetForm() {
      this.queryForm = {
        endTime: "",
        beginTime: "",
        processName: ""
      };
      this.orgShow = false;
      // this.getMescroll(0).triggerDownScroll();
    },
    contentColor(n) {
      let m = n;
      if (typeof m == "string") {
        m = Number(m);
      }
      if (typeof m == "number" && !isNaN(m)) {
        return m >= 0 ? this.normalTxtColor : this.errorTxtColor;
      }
      return this.normalTxtColor;
    },
    filterNum(n) {
      let m = n;
      if (typeof m == "string") {
        m = Number(m);
        if (isNaN(m)) {
          m = n;
        }
      }
      if (typeof m == "number" && !isNaN(m) && m != 0) {
        return m.toFixedNo(this.fixedLimit);
      }
      return m;
    },
    getScrollHeight() {
      let p = this.swiperHeight - uni.upx2px(80) + "px";
      // #ifdef H5-WECHAT
      p = this.swiperHeight + "px";
      // #endif
      return p;
    }
  }
};
</script>
<style lang="scss" scoped>
$height: 50px;
.cearch_title {
  background-color: #f3f4f5;
  width: 100%;
  height: 82rpx;
  font-size: 32rpx;
  font-weight: 600;
  padding: 22rpx 0 21rpx 32rpx;
  z-index: 999;
  position: fixed;
}

.title-content {
  width: 89%;
  margin: auto;
  padding-top: 76rpx;

  .query-btn {
    position: fixed;
    width: 95%;
    bottom: var(--window-bottom, 0);
  }
}
.slide-header-lay {
}

.head-row {
  height: 80rpx;
  width: 100%;
  background: #e0f1ff;
  display: flex;
  flex-direction: row;
  align-items: center;

  .u-row {
    height: inherit;
  }
}

.head-title-lay {
  display: flex;
  flex-direction: row;
  justify-content: center;
  align-items: center;
  width: 100%;
}

.sort-icon {
  display: grid;
  height: 20px;
  margin-left: 3px;
  font-size: 10px;
  transform: scale(0.6);
}

.split-title {
  color: #393b3d;
  font-weight: 600;
  font-size: 25rpx;
  word-break: keep-all;
  text-overflow: ellipsis;
}

.list-item {
  font-size: 26rpx;
  font-weight: 400;
  color: #393b3d;
  word-break: break-word;
}

.row-item {
  min-height: 84rpx;
  padding-top: 10rpx;
  padding-bottom: 10rpx;
  margin-bottom: 10rpx;
}

.row-item:nth-child(odd) {
  // 双行
  background-color: white;
}

.row-item:nth-child(even) {
  //单行
  background-color: #fcfcfc;
  border-bottom: 1px solid #dfe0e1 !important;
  border-top: 1px solid #dfe0e1 !important;
}

.total-row-lay {
}

.row-lay:first-child {
  // margin-top: 84rpx;
}

.taped-len {
  position: relative;
  margin-top: 5rpx;
}

.taped-item {
  background-color: #e6e6e6 !important;
  font-weight: 600;
}
</style>
